<?
//to write
$csv=file("File.csv");
  $nbcsv=count($csv);
  $file="POI.ov2";
  $fp = fopen($file, "w");
  for ($i = 0; $i < $nbcsv; $i++) {
    $table = split(",",chop($csv[$i])); // Every ligne in this type: longitude,latitude,description
    $lon = $table[0];
    $lat = $table[1];
    $des = $table[2];
    $TT = chr(0x02).pack("V",strlen($des)+14).pack("V",round($lon*100000)).pack("V",round($lat*100000)).$des.chr(0x00);
    @fwrite ($fp, "$TT");
  }
  fclose($fp);
  
  
//to read
$nbov2 = 0;
$file="POI.ov2";
$fp = fopen($file, "rb");
$type = fread($fp, 1);
$type = bin2hex($type);
while ($type == "02") {
  $len = unpack("V",fread($fp, 4));
  $len = $len[1]-14;
  $lon = unpack("V",fread($fp, 4));
  $lon = $lon[1] / 100000;
  $lat = unpack("V",fread($fp, 4));
  $lat = $lat[1] / 100000;
  $data = fread($fp, $len);
  $nbov2 = $nbov2 + 1;
  echo "type=$type lon=$lon lat=$lat data=$data\n";
  $nil = fread($fp, 1);
  $type = fread($fp, 1);
  $type = bin2hex($type);
}
fclose($fp);
echo "Nb of POIs in this file: $nbov2";

?>